using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VAKSHTYP
    {
        public DataRow Convert2AKSHTYP(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryAKSHTYP(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["AKTMANDANT"] = " ".PadRight(2 ); 
         dwReturn["AKTTYP"] = " ".PadRight(2 ); 
         dwReturn["AKTAENZL"] = " ".PadRight(0 ); 
         dwReturn["AKTAENB"] = " ".PadRight(8 ); 
         dwReturn["AKTAEND"] = " ".PadRight(0 ); 
         dwReturn["AKTNEUB"] = " ".PadRight(8 ); 
         dwReturn["AKTNEUD"] = " ".PadRight(0 ); 
         dwReturn["AKTSHSTART"] = " ".PadRight(0 ); 
         dwReturn["AKTSHENDE"] = " ".PadRight(0 ); 
         dwReturn["AKTSHGLEITZEIT"] = " ".PadRight(0 ); 
         dwReturn["AKTSHAUTOMELD"] = " ".PadRight(1 ); 
         dwReturn["AKTP1START"] = " ".PadRight(0 ); 
         dwReturn["AKTP1ENDE"] = " ".PadRight(0 ); 
         dwReturn["AKTP1BEZAHLT"] = " ".PadRight(1 ); 
         dwReturn["AKTP1MARUN"] = " ".PadRight(1 ); 
         dwReturn["AKTP1GLEITZEIT"] = " ".PadRight(0 ); 
         dwReturn["AKTP1AUTOMELD"] = " ".PadRight(1 ); 
         dwReturn["AKTP2START"] = " ".PadRight(0 ); 
         dwReturn["AKTP2ENDE"] = " ".PadRight(0 ); 
         dwReturn["AKTP2BEZAHLT"] = " ".PadRight(1 ); 
         dwReturn["AKTP2MARUN"] = " ".PadRight(1 ); 
         dwReturn["AKTP2GLEITZEIT"] = " ".PadRight(0 ); 
         dwReturn["AKTP2AUTOMELD"] = " ".PadRight(1 ); 
         dwReturn["AKTFILLER"] = " ".PadRight(83 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapAKSHTYP(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveAKSHTYP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryAKSHTYP(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapAKSHTYP(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertAKSHTYP(dwLocal, ITXDBVERSION);
            }
            UpdateAKSHTYP(dwLocal);
        }
        public void InsertAKSHTYP(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO AKSHTYP(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryAKSHTYP(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM AKSHTYP WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM AKSHTYP  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "AKSHTYP";
            Return = Result;
            return Return;
        }
        public void DeleteAKSHTYP(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM AKSHTYP   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateAKSHTYP(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE AKSHTYP SET "
                    +"AKTMANDANT= :AKTMANDANT,"
                    +"AKTTYP= :AKTTYP,"
                    +"AKTAENZL= :AKTAENZL,"
                    +"AKTAENB= :AKTAENB,"
                    +"AKTAEND= :AKTAEND,"
                    +"AKTNEUB= :AKTNEUB,"
                    +"AKTNEUD= :AKTNEUD,"
                    +"AKTSHSTART= :AKTSHSTART,"
                    +"AKTSHENDE= :AKTSHENDE,"
                    +"AKTSHGLEITZEIT= :AKTSHGLEITZEIT,"
                    +"AKTSHAUTOMELD= :AKTSHAUTOMELD,"
                    +"AKTP1START= :AKTP1START,"
                    +"AKTP1ENDE= :AKTP1ENDE,"
                    +"AKTP1BEZAHLT= :AKTP1BEZAHLT,"
                    +"AKTP1MARUN= :AKTP1MARUN,"
                    +"AKTP1GLEITZEIT= :AKTP1GLEITZEIT,"
                    +"AKTP1AUTOMELD= :AKTP1AUTOMELD,"
                    +"AKTP2START= :AKTP2START,"
                    +"AKTP2ENDE= :AKTP2ENDE,"
                    +"AKTP2BEZAHLT= :AKTP2BEZAHLT,"
                    +"AKTP2MARUN= :AKTP2MARUN,"
                    +"AKTP2GLEITZEIT= :AKTP2GLEITZEIT,"
                    +"AKTP2AUTOMELD= :AKTP2AUTOMELD,"
                    +"AKTFILLER= :AKTFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("AKTMANDANT", OracleType.NVarChar).Value = dwData["AKTMANDANT"].ToString(); 
          or1.Parameters.Add("AKTTYP", OracleType.NVarChar).Value = dwData["AKTTYP"].ToString(); 
          or1.Parameters.Add("AKTAENZL", OracleType.NVarChar).Value = dwData["AKTAENZL"].ToString(); 
          or1.Parameters.Add("AKTAENB", OracleType.NVarChar).Value = dwData["AKTAENB"].ToString(); 
          or1.Parameters.Add("AKTAEND", OracleType.NVarChar).Value = dwData["AKTAEND"].ToString(); 
          or1.Parameters.Add("AKTNEUB", OracleType.NVarChar).Value = dwData["AKTNEUB"].ToString(); 
          or1.Parameters.Add("AKTNEUD", OracleType.NVarChar).Value = dwData["AKTNEUD"].ToString(); 
          or1.Parameters.Add("AKTSHSTART", OracleType.NVarChar).Value = dwData["AKTSHSTART"].ToString(); 
          or1.Parameters.Add("AKTSHENDE", OracleType.NVarChar).Value = dwData["AKTSHENDE"].ToString(); 
          or1.Parameters.Add("AKTSHGLEITZEIT", OracleType.NVarChar).Value = dwData["AKTSHGLEITZEIT"].ToString(); 
          or1.Parameters.Add("AKTSHAUTOMELD", OracleType.NVarChar).Value = dwData["AKTSHAUTOMELD"].ToString(); 
          or1.Parameters.Add("AKTP1START", OracleType.NVarChar).Value = dwData["AKTP1START"].ToString(); 
          or1.Parameters.Add("AKTP1ENDE", OracleType.NVarChar).Value = dwData["AKTP1ENDE"].ToString(); 
          or1.Parameters.Add("AKTP1BEZAHLT", OracleType.NVarChar).Value = dwData["AKTP1BEZAHLT"].ToString(); 
          or1.Parameters.Add("AKTP1MARUN", OracleType.NVarChar).Value = dwData["AKTP1MARUN"].ToString(); 
          or1.Parameters.Add("AKTP1GLEITZEIT", OracleType.NVarChar).Value = dwData["AKTP1GLEITZEIT"].ToString(); 
          or1.Parameters.Add("AKTP1AUTOMELD", OracleType.NVarChar).Value = dwData["AKTP1AUTOMELD"].ToString(); 
          or1.Parameters.Add("AKTP2START", OracleType.NVarChar).Value = dwData["AKTP2START"].ToString(); 
          or1.Parameters.Add("AKTP2ENDE", OracleType.NVarChar).Value = dwData["AKTP2ENDE"].ToString(); 
          or1.Parameters.Add("AKTP2BEZAHLT", OracleType.NVarChar).Value = dwData["AKTP2BEZAHLT"].ToString(); 
          or1.Parameters.Add("AKTP2MARUN", OracleType.NVarChar).Value = dwData["AKTP2MARUN"].ToString(); 
          or1.Parameters.Add("AKTP2GLEITZEIT", OracleType.NVarChar).Value = dwData["AKTP2GLEITZEIT"].ToString(); 
          or1.Parameters.Add("AKTP2AUTOMELD", OracleType.NVarChar).Value = dwData["AKTP2AUTOMELD"].ToString(); 
          or1.Parameters.Add("AKTFILLER", OracleType.NVarChar).Value = dwData["AKTFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
